home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: ua302aa@sun2.lrz-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c,comp.lang.c.moderated
- Subject: Re: Leading and Trailing Blanks
- Date: 5 Jan 1996 09:52:28 -0600
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4cjhfs$f6r@solutions.solon.com>
- References: <4chh1b$685@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
-
-
- mskc@io.com (Casey Claiborne) writes:
-
-
- >Hello -
- > I am wondering if anyone out there has a program (or knows of one)
- >that allows one to strip leading and trailing blanks from a string.
- >ex:
-
- > char test[20];
- > strcpy(test," TESTING ");
- > printf("%s", test);
-
- >will produce an output like
- > TESTING
-
- >that has blanks at the beginning of "TESTING". I would like to
- >have the following result
-
- >TESTING
-
- >that has no leading blanks.
-
- >I would *greatly* appreciate any type of help or hints in working with
- >this.
-
- Try something like this:
-
-
- #include <ctype.h>
- #include <string.h>
-
- char test[BIG_ENOUGH], *beg, *end;
-
- beg = " TESTING ";
-
- /* Skip leading white space characters */
-
- while(isspace(*beg))
- ++beg;
-
- strcpy(test, beg);
-
- /* Remove trailing blanks */
-
- end = strrchr(test, '\0');
- if (end > test)
- {
- --end;
- while(isspace(*end))
- --end;
- end[1] = '\0';
- }
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
- | ua302aa@sunmail.lrz-muenchen.de
-